Daily Invoice Export
Introduction
This is an export file that consists of invoices and credits that are generated on the day of export.
Purpose
Suppliers using visn platform requires a compilation of invoices and credits that are generated on the day of export as a single which they can further use for the internal monitoring purposes and cross checking the billing issued by customers.
File format
Comma Separated Values - *.csv
Terminology
| Record Set | A set of rows exported into the CSV file, it consists of the records in the order as in below
* n denotes an index of parts/fluids added in a job line of specific enquiry | |||||||||||||||||||||||||||||||||
| Record | A particular line of the export that is either of indicators allowed in a record set, along with one record for the entire file among the following
|
Blocks
| Invoice | An invoice is a document that a supplier issues to a operator (lease), requesting payment for goods provided or services rendered. Invoices are essential for record-keeping as well. Below are examples of some goods and services that would be invoiced
|
| Credit | A Credit is a way to adjust the final amount due, ensuring that the operator(lease) only pays for what they actually owe after any agreed-upon deductions
|
Export Data Retrieval Logic
To ensure no invoices are missed due to timing issues (e.g., invoices created after the export scheduler runs), the system implements a catch-up mechanism that retrieves missed invoices from the previous day.
Timestamp Fields
Each export document includes timestamp tracking:
- Epoch Timestamp: Records when the export document is created (in epoch milliseconds)
- Readable Timestamp: A human-readable timestamp field alongside the epoch value for reference
Catch-Up Logic (when obtainFullDaysExport is false)
When the export process is triggered:
Capture Trigger Time: The current epoch timestamp is captured immediately when the scheduler is triggered. This timestamp is used as the reference point for all time calculations.
Calculate Time Window: The system calculates the time window for the previous 24 hours:
const timeSinceLastExport = currentEpoch - 24 * 60 * 60
Retrieve Missed Documents: The system queries the previous day's collection for any documents that may have been missed by comparing their timestamps against
timeSinceLastExport.Append to Current Export: Any missed documents from the previous day are appended to the current day's invoice export.
Filter Current Day Data: When fetching the current day's exports, the system filters by an end time to ensure no exports created during the export generation process are included. These will be picked up in the next day's export.
Full Day Export (when obtainFullDaysExport = true)
When obtainFullDaysExport is set to true:
- The catch-up logic is bypassed
- All data for the specified day in the collection is fetched without any time filtering
- This mode is useful for manual invoice generation for a specific day without catch-up logic
Setup Required
Database Configuration
Although this export is targeted to any lease company, The use of External SMR Codes is limited to few lease companies.
To prevent the external SMR Codes in the daily invoice export for all lease companies a , A flag needs to be enabled in the lease company's export configuration to restrict the usage of external SMR
location: /leasecompany/[leaseId]
attribute: includeExternalSMRCodesInExport
value: true
Note: This step is optional as there is provision available for enabling the same from Edit Customer Screen of DI Admin Portal
Generate Export
A Scheduler should be created cloud scheduler with the following parameters
- Name: Generate daily invoice export
- Region: europe-west2
- Frequency: 30 23 * * *
- TimeZone: GMT London
- Topic: projects/biddirect-2/topics/generateDailyInvoiceExport
Message body: a JSON object including the following parameters
- dateTimeStamp: in format yyyy-MMM-dd ex 2022-Sep-30 , when skipped it will default to current date
- leaseCompanyId: id of the lease company that the export is desired to be generated for
- exportFileName: file name prefix to be used for the export file generated, when skipped defaults to 'invoice'
- addLCLineForInvoice:
- True: When set to true, an LC line is included for each record in the file.
- False: When set to false, a single LC line is included for the entire file.
obtainFullDaysExport: (optional, default: false)
- False: Enables catch-up logic to fetch missed invoices from previous day using time window calculation
- True: Bypasses catch-up logic and fetches all data for the specified day without any time filtering
Note: This is useful for manual invoice generation for a specific day without catch-up logic